package com.wzdigit.wms.wms.controller.inventory;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.domain.dtos.inventory.SnInforDto;
import com.wzdigit.wms.basic.client.request.downaway.SubmitDownAwayRequest;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.order.DownAwayService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 下架
 * @author Administrator
 *
 */
@RestController
@Api(tags = "下架")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class DownAwayController {

	private static final String REQUEST_MODEL = "/Inventory/DownAway";
    
    @Autowired
    private DownAwayService downAwayService;

    /**
     * 扫描sn
     *
     * @return
     */
    @ApiOperation(value = "扫描SN", notes = "扫描SN")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/scanSn", method = RequestMethod.GET)
    public Result<List<SnInforDto>> scanSn(
    		@ApiParam("产品SN") String sn, 
    		@ApiParam("扫描方式（单台：0、整版：1）") Integer twScanMode,
    		HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return downAwayService.scanSn(sn, twScanMode);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    /**
     * 提交下架
     *
     * @return
     * @throws Exception 
     */
    @ApiOperation(value = "提交下架", notes = "提交下架")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/submit", method = RequestMethod.POST)
    public Result<String> submit(
    		@RequestBody @Valid SubmitDownAwayRequest input,
    		HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception {
        try {
        	return downAwayService.submit(input, servletRequest);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
}
